package accesslog_service

import (
	"errors"
	"os"
	"starry_sky/internal/config"
	"starry_sky/internal/tools/logger"
	"strings"
)

func GetAccessLogFileList() ([]map[string]string, error) {
	files, err := os.ReadDir(config.LogConfig.WebLogConfig.Path)
	if logger.HasError(err, "打开文件夹异常") {
		return nil, errors.New("系统日志文件夹打开异常")
	} else {
		var fileNameList []map[string]string
		for _, file := range files {
			returnMap := make(map[string]string)
			returnMap["fileName"] = strings.Split(file.Name(), ".")[0]
			fileNameList = append(fileNameList, returnMap)
		}
		return fileNameList, nil
	}
}
